package com.suxin;

import com.suxin.servlet.TestServlet;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;

import java.io.File;

/**
 * @Classname App
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2021/1/6 10:47
 * @Created by ASUS
 */
public class App {

    public static void main(String[] args) {

        Tomcat tomcat = new Tomcat();

        tomcat.setPort(8081);

        File file = new File(System.getProperty("java.io.tmpdir"));

        tomcat.addContext("/",file.getAbsolutePath());

        Connector connector = tomcat.getConnector();

        System.out.println("连接器设置完成：" + connector);

        Wrapper testServlet = tomcat.addServlet("/", "testServlet",
                new TestServlet());
        testServlet.addMapping("/testServlet");

        try {
            tomcat.start();
            tomcat.getServer().await();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }

    }

}